| Total Complexity | 2 |
| Total Lines | 28 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import { CommandHandler } from '@nestjs/cqrs'; |
||
| 6 | |||
| 7 | @CommandHandler(UpdateContactCommand) |
||
| 8 | export class UpdateContactCommandHandler { |
||
| 9 | constructor( |
||
| 10 | @Inject('IContactRepository') |
||
| 11 | private readonly contactRepository: IContactRepository |
||
| 12 | ) {} |
||
| 13 | |||
| 14 | public async execute(command: UpdateContactCommand): Promise<void> { |
||
| 15 | const { |
||
| 16 | id, |
||
| 17 | firstName, |
||
| 18 | lastName, |
||
| 19 | company, |
||
| 20 | email, |
||
| 21 | phoneNumber, |
||
| 22 | notes |
||
| 23 | } = command; |
||
| 24 | |||
| 25 | const contact = await this.contactRepository.findOneById(id); |
||
| 26 | |||
| 27 | if (!contact) { |
||
| 28 | throw new ContactNotFoundException(); |
||
| 29 | } |
||
| 30 | |||
| 31 | contact.update(firstName, lastName, company, email, phoneNumber, notes); |
||
| 32 | |||
| 33 | await this.contactRepository.save(contact); |
||
| 34 | } |
||
| 36 |